function add0(m) {
	return m < 10 ? '0' + m : m
}

function format(shijianchuo) {
	//shijianchuo是整数，否则要parseInt转换
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}
export function formatTime(time) {
	if (time != null) {
		let d = time.replace('T', ' ').replace('.000Z', '')
		let d2 = Date.parse(d) + 3600 * 8 * 1000;
		const now = Date.now()
		const diff = (now - d2) / 1000
		if (diff < 60) {
			return '刚刚'
		} else if (diff < 3600) { // less 1 hour
			return Math.ceil(diff / 60) + '分钟前'
		} else if (diff < 3600 * 24) {
			return Math.ceil(diff / 3600) + '小时前'
		} else if (diff < 3600 * 24 * 2) {
			return '1天前'
		} else {
			return format(d2)
		}
	}

	return null;


}
